package com.usian.article.rabbitmq;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.usian.article.service.ApArticleConfigService;
import com.usian.common.exception.CatchCustomException;
import com.usian.common.exception.code.UserStatusCode;
import com.usian.model.article.pojos.ApArticleConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;


@Component
@SuppressWarnings("ALL")
public class RealnameAuthMQ {
    @Autowired
    private ApArticleConfigService apArticleConfigService;
    //监听方法  routingkey
    @RabbitListener(queues = "DownOrUpQueue")
    public void authMQ(Map map) throws IOException {
        Long articleId = (long)map.get("article_id");
        Integer ee = (int)map.get("enable");
        ApArticleConfig apArticleConfig = new ApArticleConfig();
        apArticleConfig.setArticleId(articleId);
//        Boolean.getBoolean("true"); // true
//        Boolean.getBoolean("True"); // false
//        Boolean.parseBoolean("True");// true
        Boolean enable = null;
        if (ee == 0){
            enable = false;
        }else if (ee == 1){
            enable = true;
        }else {
            CatchCustomException.catchs(UserStatusCode.PARAM_FAIL,"上下架状态有误！！！");
        }

        apArticleConfig.setIsDown(enable);

        // update ap_articleconfig set is_down=？ where article_id=?
        LambdaUpdateWrapper<ApArticleConfig> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ApArticleConfig::getArticleId,apArticleConfig.getArticleId());
        updateWrapper.set(ApArticleConfig::getIsDown,apArticleConfig.getIsDown());
        apArticleConfigService.update(updateWrapper);
    }


}
